package cn.edu.jlu.community.disuse;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import cn.edu.jlu.community.R;
import cn.edu.jlu.community.disuse.activity.SimpleCardFragment;
import cn.edu.jlu.community.app.base.AbstractListFragment;

/**
 * A {@link android.support.v4.app.FragmentPagerAdapter} that returns a fragment corresponding to
 * one of the sections/tabs/pages.
 */
public class HomePagerAdapter extends FragmentPagerAdapter {

    private static final int[] TITLES = {
            R.string.page_title_news,
            R.string.page_title_bbs,
            R.string.page_title_more,
    };

    private Context mContext;

    public HomePagerAdapter(FragmentManager fm, Context context) {
        super(fm);
        mContext = context;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mContext.getString(TITLES[position]);
    }

    @Override
    public int getCount() {
        return TITLES.length;
    }

    @Override
    public Fragment getItem(int position) {
        final AbstractListFragment fragment;
        switch (position) {
            case 0:
                fragment = HomeTimelineFragment.newInstance();
                break;
            default:
                return SimpleCardFragment.newInstance(position);
        }
        return fragment;
    }
}
